<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib uri="/tld/dictionary" prefix="dictionary"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>撮合交易</title>
<link rel="stylesheet" href="${ctx}/static/css/style.css" type="text/css" /> 
<link rel="stylesheet" href="${ctx}/static/css/kongjian.css" type="text/css" /> 
<link rel="stylesheet" href="${ctx}/static/css/m.css" type="text/css" /> 
<link rel="stylesheet" href="${ctx}/static/css/jquery.ui.all.css" />
<script src="${ctx}/static/script/jquery-1.4.min.js" type="text/javascript"></script>
<script src="${ctx}/static/script/jquery.ui.core.js"></script>
<script src="${ctx}/static/script/jquery.ui.datepicker.js"></script>
<script src="${ctx}/static/script/jsCoreUtil.js"></script>
<script src="${ctx}/static/script/jquery.form.js"></script>
<script type="text/javascript" src="${ctx}/static/script/jquery.blockUI.js" ></script>
<script language="javascript">
function bb(x){
	var tablename ;
	setCommendValue(RecommValueMap);
	
    //撮合
    if(x==1){
    	var thisform = document.getElementById('mainform1');
    	thisform.pageNo.value = 1;
	    tablename = 'no_recommend_table';
		ajaxsubmitRecommend('new');
    }else if(x==2){
   		var thisform  = document.getElementById('mainform2');
    	thisform.pageNo.value = 1;
    	var tablename = 'has_recommend_table';
    	ajaxsubmitHasRecommend();
    }
    
	for(i=1;i<3;i++){
		
		document.getElementById("t"+i).style.display="none";
		document.getElementById("a_m"+i).style.background="#fff";
		}
		document.getElementById("t"+x).style.display="block";
		document.getElementById("a_m"+x).style.background="#c6defa";
	}
</script>
<script type="text/javascript">
function jine(str){
    if(!/^((\d{1,3}(,\d{3})*)|(\d+))(\.\d{1,2})?$/.test(str)) {  
        alert("请输入正确金额数!");
	}
}
</script>
</head>

<body style="margin:10px;">
<form:form id="mainform1" action="#"  modelAttribute="recommendInfoForm" method="post" >
<p style=" text-align:left; height:30px; padding:0 10px; line-height:30px; border:#3b97e4 solid 1px;">
投资编号：${recommendInfoForm.investInfo.id} 
客户编号：${recommendInfoForm.investInfo.customerInfo.customerCode} 
客户姓名：${recommendInfoForm.investInfo.customerInfo.cnName} 
<c:if test="${recommendInfoForm.investInfo.regularType=='00130001'}">
<input type="hidden" name="recommenddate" id="recommenddate" value="<fmt:formatDate value="${recommendInfoForm.investInfo.investStartDate}"   pattern="yyyy-MM-dd" type="date" dateStyle="long" />"/>
	投资金额：<fmt:formatNumber value="${recommendInfoForm.investInfo.investAmt}" pattern="##,###.##" /> 
	交割日期：
	<fmt:formatDate value="${recommendInfoForm.investInfo.investStartDate}"   pattern="yyyy-MM-dd" type="date" dateStyle="long" />
</c:if>
<c:if test="${recommendInfoForm.investInfo.regularType=='00130002'}">
<input type="hidden" name="recommenddate" id="recommenddate" value="<fmt:formatDate value="${recommendInfoForm.investInfo.regularStartDate}"   pattern="yyyy-MM-dd" type="date" dateStyle="long" />"/>
	投资金额：<fmt:formatNumber value="${recommendInfoForm.investInfo.regularAmt}" pattern="##,###.##" /> 
	交割日期：
	<fmt:formatDate value="${recommendInfoForm.investInfo.regularStartDate}"   pattern="yyyy-MM-dd" type="date" dateStyle="long" />
</c:if>
</p>
<div style="height:10px;"></div>
<p>
<a id="a_m1"  class="a_m">可交易债权</a><!-- onclick="bb(1)"  -->
<a id="a_m2"  class="a_m" style="background:#fff; border-left:0;">已撮合债权</a></p><!-- onclick="bb(2)" -->
<div id="errormsg_show_div" class="notification error png_bg" style="display:none;" >
<a href="#" class="close"><img src="${ctx}/static/images/icons/cross_grey_small.png" title="Close this notification" alt="close" /></a>
<font color='red'><div id='errormsg_info_div'  align='left'></div></font>
</div>
<input type="hidden" name="recommendtag" id="recommendtag" value=""/>
<input type="hidden" name="noRecommendValue" id="noRecommendValue" value=""/>
<input type="hidden" name="investId" id="investId" value="${recommendInfoForm.investId}"/>
<input type="hidden" name="investAmt" id="investAmt" value="${recommendInfoForm.investAmt}"/>
<input type="hidden" name="regularAmt" id="regularAmt" value="${recommendInfoForm.regularAmt}"/>
<input type="hidden" name="regulartype" id="regulartype" value="${recommendInfoForm.regularType}"/>
<input type="hidden" name="orderdtlIds" id="orderdtlIds" value="${recommendInfoForm.orderdtlIds}"/>

<div id="output1" />
<div style="clear:both;"></div>
<div style=" border:#3b97e4 solid 1px; padding:10px 0 20px;" id="t1">
   <div class="shenqing2">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
	     <tr>
            <td width="61">债权编号：</td>
            <td width="150px" style="color:#2E74D1;"><input type="text" name="loanId" id="loanId" class="ggkj_inputtext_80" value="${recommendInfoForm.loanId}" /></td>
            <td width="85">债务人：</td>
            <td width="150px" style="color:#2E74D1;"><input type="text" name="loanCustomerName" id="loanCustomerName" class="ggkj_inputtext_80" value="${recommendInfoForm.loanCustomerName}" />
            </td>
			<td width="85">收益率：</td>
             <td width="250px" style="color:#2E74D1;">
             	<input type="text" id="irrMin" name="irrMin" value="${recommendInfoForm.irrMin}"  class="ggkj_inputtext_80" value="10%" />-
             	<input type="text" id="irrMax" name="irrMax" value="${recommendInfoForm.irrMax}"  class="ggkj_inputtext_80" value="10%" />
           </td>
			<td width="85">借款产品：</td>
            <td width="150px" style="color:#2E74D1;">
             <select id="product"  name="product">
             <option value="" selected="true">请选择</option>
             <option value="1001">随房贷</option>
	         <option value="1002">随意贷</option>
	         <option value="1003">随薪贷</option>
	         <option value="1004">随车贷</option>
	         <option value="1005">其他</option>   	
				</select>
            </td>
			 <td width="93"><input name="Input" type="button" class="chaxun_btn" value="&nbsp;&nbsp;查询" onclick="ajaxsubmitRecommend('new')"/>
             </td>
          </tr>
      </table>
    </div>
	<p style="padding-left:16px;">
	<input  type="button" id="recommend_button" name="recommend_button" onclick="recommend()"  value="撮合" style="border:1px solid #3b97e4; background:#fff; display:block; width:80px; height:20px; line-height:20px; background:#c6defa; color:#000; float:left; margin-top:10px;">
	</input>
	</p>
    <div style="clear:both;"></div>
	<div class="yiban">
<div id="mainform1table_div"></div>	
</div>
	<div class="yiban"><div id="mainform3table_div" ></div></div>
	<table width="100%" id="no_recommend_table" name="no_recommend_table"  style="width:100%;" class="ggkj_table"  border="0" cellspacing="0" cellpadding="0"></table>
	<div class="ggkj_pagecontainer">
	  <div class="ggkj_pageBGleft">
			<span class="ggkj_pageBGright"></span>
			<a href="javascript:jumpPage(1)" class="ggkj_pageUpa">
			
			</a>
			<a href="javascript:jumpPage(mainform1_page.prePage)" class="ggkj_pageUp">
			
			</a>
			<span class="ggkj_insertline"></span>
			<span class="ggkj_pageSpan">
				页
				<input type="text" id="pageNo" name="pageNo" value="1" class="ggkj_inputtext_30" />OF <span id="totalPages1">0</span>
			</span>
			<span class="ggkj_insertline"></span>
			<a href="javascript:jumpPage(mainform1_page.nextPage)" class="ggkj_pageDown">
			</a>
			<a href="javascript:jumpPage(mainform1_page.totalPages)" class="ggkj_pageDowna">
			
			</a>
			<span class="ggkj_insertline"></span>
		</div>
	</div>
</div>
</form:form>
<form:form id="mainform2" action="#" modelAttribute="recommendInfoForm"  method="post" >  
<input type="hidden" name="deliveryDate" id="deliveryDate" value="<fmt:formatDate value="${recommendInfoForm.deliveryDate}" type="date"/>" />
<input type="hidden"  id="id" name="id" value="${recommendInfoForm.id}"/>
<input type="hidden" name="recommendtag" id="recommendtag" />
<input type="hidden" name="recommendValue" id="recommendValue" />
<input type="hidden" name="investIdOld" id="investIdOld" value="${recommendInfoForm.investId}"/>
<div id="output2" /> 
<div style=" border:#3b97e4 solid 1px; padding:10px 0 20px;" id="t2">
    <!--
   <div class="shenqing2">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
	     <tr>
            <td width="61">债权编号：</td>
            <td width="150px" style="color:#2E74D1;"><input type="text" name="loanId" id="loanId" class="ggkj_inputtext_80" value="${recommendInfoForm.loanId}" /></td>
            <td width="85">债务人：</td>
            <td width="150px" style="color:#2E74D1;"><input type="text" name="loanCustomerName" id="loanCustomerName" class="ggkj_inputtext_80" value="${recommendInfoForm.loanCustomerName}" />
            </td>
			<td width="85">收益率：</td>
           <td width="250px" style="color:#2E74D1;">
             	<input type="text" id="irrMin" name="irrMin" value="${recommendInfoForm.irrMin}"  class="ggkj_inputtext_80" value="10%" />-
             	<input type="text" id="irrMax" name="irrMax" value="${recommendInfoForm.irrMax}"  class="ggkj_inputtext_80" value="10%" />
           </td>
			<td width="85">借款产品：</td>
             <td width="150px" style="color:#2E74D1;">
             <select id="product"  name="product">
             <option value="" selected="true">请选择</option>
             <option value="1001">随房贷</option>
	         <option value="1002">随意贷</option>
	         <option value="1003">随薪贷</option>
	         <option value="1004">随车贷</option>
	         <option value="1005">其他</option>   	
				</select>
            </td>
			 <td width="93"><input name="Input" type="button" class="chaxun_btn" value="&nbsp;&nbsp;查询" onclick="ajaxsubmitRecommend('new')"/>
             </td>
          </tr>
           
      </table>
    </div>
    -->
	<p style="padding-left:16px;">
	<input id="recommend_save_button" name="recommend_save_button" type="button" value="保存" onClick="saveRecommend()"  style="border:1px solid #3b97e4; background:#fff; display:block; width:80px; height:20px; margin-right:15px; line-height:20px; background:#c6defa; color:#000; float:left; margin-top:10px;"/>
	<input id="recommend_delete_button" name="recommend_delete_button" style='display:none;' type="button" value="删除" onClick="deleteRecommend()" style="border:1px solid #3b97e4; background:#fff; display:block; width:80px; height:20px; line-height:20px; background:#c6defa; color:#000; float:left; margin-top:10px;"/></p>
    <div style="clear:both;"></div>
	<div class="yiban">
<div id="mainform2table_div"></div>	
	
</div>
<!-- 
<div class="ggkj_pagecontainer">
  <div class="ggkj_pageBGleft">
    	<span class="ggkj_pageBGright"></span>
    	<a href="#" class="ggkj_pageUpa">
        
        </a>
        <a href="#" class="ggkj_pageUp">
        
        </a>
        <span class="ggkj_insertline"></span>
        <span class="ggkj_pageSpan">
        	页
        </span>
        <span class="ggkj_insertline"></span>
        <a href="#" class="ggkj_pageDown">
        
        </a>
        <a href="#" class="ggkj_pageDowna">
        
        </a>
        <span class="ggkj_insertline"></span>
        <input type="text" id="pageNo" name="pageNo" value="1" class="ggkj_inputtext_30" type='hidden'/>OF <span id="totalPages2">0</span>
    </div>
</div>
 -->
        	<input id="pageNo" name="pageNo" value="1" class="ggkj_inputtext_30" type='hidden'/>
</form:form>
</div>


<script type="text/javascript">
//页面js 参数初始化
var map = new CoreMap(); 
var recommendmap = new CoreMap(); 
var RecommValueMap = new CoreMap(); //撮合勾选数据
var HasRecommValueMap = new CoreMap(); //已撮合数据
var RecommendErrorData = new CoreMap(); //推荐比例大于可推荐比例数据存储器
var requestPage ;
var customerManagerId=1; 
var mainform1_page ; //page object
var mainform2_page ; //page object
var dictionary = new CoreMap();
var hasRecommendSize=0;
$(document).ready(function(){
	dictionary=dictionaryInit();
});

//全选Checkbox
function allChecked(formname,checkboxname) {
    var thisform = document.getElementById(formname);
    var ids = document.getElementsByName(checkboxname);
    var isChecked = false;
    var mapv = new CoreMap();
    var formpage ;
    if(checkboxname=='recommendid1'){
	    RecommValueMap = AllCheckedByCheckBoxNamePutValueByAutoAllCheck(formname,checkboxname,RecommValueMap,getRecommendNameArray());
    }else{
	    HasRecommValueMap = AllCheckedByCheckBoxNamePutValueByAutoAllCheck(formname,checkboxname,RecommValueMap,getRecommendNameArray());
    }
    
    if(formname=='mainform1'){
    	mapv = map;
    	formpage = mainform1_page;
    }else if(formname=='mainform2'){
    	mapv = recommendmap;
    	formpage = mainform2_page;
    }
    if (thisform.num.checked == true) {
        for (var i = 0; i < ids.length; i++) {
            ids[i].checked = true;
        }
    	for(var k=0;k<formpage.result.length;k++){
    		var entity = formpage.result[k];
    	}
    } else {
        for (var i = 0; i < ids.length; i++) {
            ids[i].checked = false;
        }
        for(var k=0;k<formpage.result.length;k++){
    		var entity = formpage.result[k];
    	}
    }
    //mapcount();
}

//单选Checkbox
function singleChecked(formname,checkboxname) {
    var thisform = document.getElementById(formname);
    var ids = document.getElementsByName(checkboxname);
    var isChecked = false;
    var mapv = new CoreMap();
    var formpage ;
    
    if(formname=='mainform1'){
    	mapv = map;
    	formpage = mainform1_page;
    }else if(formname=='mainform2'){
    	mapv = recommendmap;
    	formpage = mainform2_page;
    }
    if (thisform.num.checked == true) {
        for (var i = 0; i < ids.length; i++) {
            ids[i].checked = true;
        }
    	for(var k=0;k<formpage.result.length;k++){
    		var entity = formpage.result[k];
    		mapv.put(entity.ftTSellOrderDtl.id.toString(),$('#'+entity.ftTSellOrderDtl.id).val() );
    	}
    } else {
        for (var i = 0; i < ids.length; i++) {
            ids[i].checked = false;
        }
        for(var k=0;k<formpage.result.length;k++){
    		var entity = formpage.result[k];
    		mapv.remove(entity.ftTSellOrderDtl.id.toString());
    	}
    }
    //mapcount();
}

//撮合操作
function recommend(){
	//recommend init Check
	
	if(!checkrecommendData()){
		return ;
	}

	recommendmap.arr = new Array();
	bb(2);
}

function checkrecommendData(){
	var totalAmt = 0;
	var amt = 0;
	var regulartype = $('#regulartype').val();
	
	for(var m1=0;m1<RecommendErrorData.arr.length;m1++){
		var keyv = RecommendErrorData.arr[m1].key;
		if(RecommValueMap.get(keyv)!=null){
			alert('撮合勾选数据中含有异常数据(撮合比例不能大于可推荐比例!)');
			return false;
		}
	}
	
	if('00130002'==regulartype){
		amt =$('#regularAmt').val(); 
	}else if('00130001'==regulartype){
		amt =$('#investAmt').val(); 
	}
	
	for(var m=0;m<RecommValueMap.arr.length;m++){
		totalAmt = totalAmt + Number(RecommValueMap.arr[m].value[11]);
		if(RecommValueMap.arr[m].value[11]==0){
			alert('撮合债权中含有零值的投资!');
			return false;
		}
		if(!/^((\d{1,3}(,\d{3})*)|(\d+))(\.\d{1,2})?$/.test(RecommValueMap.arr[m].value[11])) {  
	        alert("请输入正确金额数!");
	        return false;
		}
	}
	
	if(Number(amt)!=totalAmt.toFixed(2)){
		alert("总推荐金额不等于投资金额 (投资金额为: "+amt+",总推荐金额为:"+totalAmt.toFixed(2)+",差值:"+(Number(amt) - totalAmt.toFixed(2))+")");
		return false;
	}
	return true;
}

//删除操作
function deleteRecommend(){
	var tempmap = new CoreMap();
	tempmap.arr = map.arr;
	for(var i=0;i<recommendmap.arr.length;i++){
		tempmap.remove(recommendmap.arr[i].key.toString());
	}
	recommendmap.arr = tempmap.arr;
	var thisform = $('#mainform2');
	var tablename = 'has_recommend_table';
	setCommendValue(RecommValueMap);
	ajaxsubmitHasRecommend();
}


//保存撮合数据
function saveRecommend(){
	var thisform = document.getElementById('mainform2');
	thisform.action = '${ctx}/recommend/recommend_add';
		if(!checkrecommendData()){
		return ;
	}
	setCommendValue(RecommValueMap);
	thisform.submit();
}

function setCommendValue(mapv){
	var vArray = RecommValueMap.arr;
	var recommendv='' ;
	for(var i=0;i<vArray.length;i++){
		recommendv = recommendv +vArray[i].value[11]+":"+vArray[i].value[13]+":"+vArray[i].value[1]+":"+vArray[i].value[14]+"#";
	}
	var thisform = document.getElementById('mainform2');
	thisform.recommendValue.value=recommendv;
	var thisform = document.getElementById('mainform1');
	thisform.noRecommendValue.value=recommendv;
}

function setNoRecommendValue(mapv){
	var vArray = mapv.arr;
	var recommendv='' ;
	for(var i=0;i<vArray.length;i++){
		recommendv = recommendv +  vArray[i].key+':'+vArray[i].value+'#';
	}
	var thisform = document.getElementById('mainform1');
	thisform.noRecommendValue.value=recommendv;
	//alert(recommendv);
}


//勾选撮合数据
function checkRecommend(v){
	var ids =document.getElementsByName('_recommendid1');
	var nameArray = getRecommendNameArray();
	for(var m=0;m<ids.length;m++){
		var key = ids[m].value.toString();
		if(ids[m].checked==true){
			var lineValue = new Array(); 
			for(var k=0;k<nameArray.length;k++){
				var inputtype = nameArray[k].split(':');
				var id =  inputtype[0] + key;
				if('div'==inputtype[1] || 'span'==inputtype[1] ){
					lineValue[k] = GetDivValue(id.toString());
				}else if('input'==inputtype[1]){
					lineValue[k] = GetInputValue(id.toString());
				}
			}
			RecommValueMap.put(key,lineValue);
		}else{
			RecommValueMap.remove(key);
		}
	}
	
	CheckBoxAlreadyChecked('_recommendid1','num');
}

//撮合后数据
function checkRecommended(v){
	if(v.checked){
		recommendmap.put(v.value.toString(),$('#'+v.value).val()
		+":"+GetInputValue("loanid"+v.value)
		+":"+GetInputValue("cs2"+v.value));
	}else{
		recommendmap.remove(v.value.toString());
	}
}


function mapcount(){
	
	var ss = '';
	for(var i=0;i<map.arr.length;i++){
		ss = ss+ map.arr[i].key+"   ";
		//alert("map key  = |"+map.arr[i].key+"|  map value  = |"+map.arr[i].value+"|");
	}
	alert(ss);
};
 
function showRequest(formData, jqForm, options) { 
    var queryString = $.param(formData); 
    alert('About to submit: \n\n' + queryString); 
    return true; 
} 

//债权信息查询
function ajaxsearchLoad(loanId){
	var loadinfo ;
	$.get('${ctx}/recommend/ajax_search_load?loanId='+loanId, function(data) {
		loadinfo = data;
	}); 
	return loadinfo;
}


//可交易债权
function ajaxsubmitRecommend(code){
	if(code=='new'){
		$("#pageNo").val(1);
	}
	var patrn=/[0-9]+[.[0-9]+]?/;
	var irrMin=document.getElementById("irrMin");
	var irrMax=document.getElementById("irrMax");
	if(irrMin.value!=""){
		if (!patrn.test(irrMin.value)) {
			alert("收益率必须是正小数！");
			return false;
		}
	} 
	if(irrMax.value!=""){
		if (!patrn.test(irrMax.value)) {
			alert("收益率必须是正小数！");
			return false;
		}
	} 
	var thisformm = document.getElementById('mainform1');
	thisformm.recommend_button.disabled=true;
    var options = {   
        target:        '#output2',   // target element(s) to be updated with server response   
        //beforeSubmit:  showRequest,  // pre-submit callback   
        success:       showmainform1response , // post-submit callback   
        // other available options:   
        url:        '${ctx}/recommend/findPageAjaxNoRecommend',      // override for form's 'action' attribute   
        type:       'post',       // 'get' or 'post', override for form's 'method' attribute   
        dataType:   'json'       // 'xml', 'script', or 'json' (expected server response type)
    };   
     // bind to the form's submit event   
    function submitt() {   
        $('#mainform1').ajaxSubmit(options);   
        return false;   
    };  
    submitt();
}
document.body.onkeypress=function() 
{ 
    if   (event.keyCode   ==13){ 
		ajaxsubmitRecommend('new');
    }	
}


function ajaxsubmitHasRecommend2(){
	var thisformm = document.getElementById('mainform2');
	thisformm.recommend_delete_button.disabled=true;
	thisformm.recommend_save_button.disabled=true;
   var options = {   
        target:     '#output2',   // target element(s) to be updated with server response   
        //beforeSubmit:  showRequest,  // pre-submit callback   
        success:    showmainform2response, // post-submit callback   
   
        // other available options:   
        url:        '${ctx}/recommend/findPageAjaxHasRecommend'  ,      // override for form's 'action' attribute   
        type:       'post',       // 'get' or 'post', override for form's 'method' attribute   
        dataType:   'json'       // 'xml', 'script', or 'json' (expected server response type)   
    }; 
   
     // bind to the form's submit event   
    function submitt() {   
        // inside event callbacks 'this' is the DOM element so we first   
        // wrap it in a jQuery object and then invoke ajaxSubmit   
        $('#mainform2').ajaxSubmit(options);   
        // !!! Important !!!   
        // always return false to prevent standard browser submit and page navigation   
        return false;   
    };  
    submitt();
}

function ajaxsubmitHasRecommend(){
	var thisformm = document.getElementById('mainform2');
	var cssName = '';
	var td = '';
    var inde = 0;
	var table ='';
	table = table + "<table style='width:100%;' id='mainform2table' name='mainform2table' class='ggkj_table'  border='0' cellspacing='0' cellpadding='0'> ";
	table = table + createmainform2title();
	for(var i=0;i<RecommValueMap.arr.length;i++){
		var recommv = RecommValueMap.arr[i];
		 if(Number(i)%2==1){
		 	cssName = 'ggkj_tdColr';
		 }else{
		 	cssName = '';
		 }
		 inde++;
		 td = td + "<tr class='"+cssName+"' >";
	  	 td = td +"<td>"+recommv.value[0]+"<input type='checkbox' name='_recommendid2' style='display:none;' value= '"+recommv.value[13]+"'/></td>";
		 td = td +"<td height='34'>"+recommv.value[1]+"</td>";
		 td = td +"<td height='34'>"+recommv.value[2]+"</td>";
		 td = td +"<td height='34'>"+recommv.value[3]+"</td>";
		 td = td +"<td height='34'>"+recommv.value[4]+"</td>";
		 td = td +"<td height='34'>"+recommv.value[5]+"</td>";
		 td = td +"<td height='34'>"+recommv.value[6]+"</td>";
		 td = td +"<td height='34'>"+recommv.value[7]+"</td>";
		 td = td +"<td height='34'>"+recommv.value[8]+"</td>";
		 td = td +"<td height='34'>"+recommv.value[9]+"</td>";
		 td = td +"<td height='34'>"+recommv.value[10]+"</td>";
		 td = td +"<td height='34'><input readonly='true' value='"+recommv.value[11]+"' size='10'/></td>";
		 td = td +"<td height='34'>"+recommv.value[12]+"</td>";
		 td = td + "</tr>";
	}
	
	for(var m=inde;m<10;m++){
		td = td + mainformInsertRow2Blank(m+1);
	}
	table =table +  td +  "</table>";
	document.getElementById('mainform2table_div').innerHTML = table;
}

//分页跳转

function jumpPage2(pageNo) {
	var thisform = document.getElementById('mainform2');
	thisform.pageNo.value = pageNo.toString();
	ajaxsubmitHasRecommend();
}

function jumpPage(pageNo) {
	var thisform = document.getElementById('mainform1');
	thisform.pageNo.value = pageNo.toString();
	ajaxsubmitRecommend('old');
}

/** 可交易债权 start*/
function createmainform1title(){
	 var tableStr = '';
	 tableStr  = tableStr +"<tr>";
	 tableStr  = tableStr +"<th scope='col'>序号<input  type='checkbox' id='num' name='num' onclick='javascript:allChecked("+'"mainform1"'+','+'"_recommendid1"'+");' /></th>";
	 tableStr  = tableStr +"<th scope='col'>债权编号</th>";
	 tableStr  = tableStr +"<th scope='col'>债务人</th>";
	 tableStr  = tableStr +"<th scope='col'>债务本金</th>";
	 tableStr  = tableStr +"<th scope='col'>可推荐比例</th>";
	 tableStr  = tableStr +"<th scope='col'>可推荐金额</th>";
	 tableStr  = tableStr +"<th scope='col'>还款期数</th>";
	 tableStr  = tableStr +"<th scope='col'>剩余期数</th>";
	 tableStr  = tableStr +"<th scope='col'>irr</th>";
	 tableStr  = tableStr +"<th scope='col'>还款日</th>";
	 tableStr  = tableStr +"<th scope='col'>借款产品</th>";
	 tableStr  = tableStr +"<th scope='col'>推荐金额</th>";
	 tableStr  = tableStr +"<th scope='col'>推荐比例</th>";
	  tableStr  = tableStr +"</tr>";
	 return tableStr;
}

function createmainform1Rows(tbIndex,data){
	//data is Transaction object
	 if(data==null || data.loanInfo ==null || data.loanInfo.customer==null || data.ftTSellOrderDtl==null || data.investInfo==null){
		//alert('data '+data +'data.loanInfo='+data.loanInfo+'   data.loanInfo.customer=' +data.loanInfo +'  data.ftTSellOrderDtl= '+data.ftTSellOrderDtl+'   data.investInfo='+data.investInfo);
	 	alert('值对象为空，js无法获取底层属性值.'+data);
	 	return ;
	 }
	 var divid = "div"+data.ftTSellOrderDtl.id+"";
	 
	 var cssName = '';
	 var td = '';
	 if(Number(tbIndex)%2==1){
	 	cssName = 'ggkj_tdColr';
	 }else{
	 	cssName = '';
	 }
	 td = td + "<tr class='"+cssName+"' >";
	 var isChecked= '';
	 //mapcount();
	 if(RecommValueMap.get(data.ftTSellOrderDtl.id.toString())!=null || RecommValueMap.get(data.ftTSellOrderDtl.id.toString())==''){
	 	isChecked = 'checked';
	 }
	 var loanCode="";
	 if(data.loanCode=='1001'){
	 	loanCode="随房贷";
	 }
	 	
	 if(data.loanCode=='1002'){
	 	loanCode="随意贷";
	 }
	 if(data.loanCode=='1003'){
	 	loanCode="随薪贷";
	 }
	 if(data.loanCode=='1004'){
	 	loanCode="随车贷";
	 }
	 if (data.loanCode=='1005'){
	 	loanCode="其他";
	 }
	 tbIndex = Number((mainform1_page.pageNo-1)*10)+Number(tbIndex);
  	 var amt_ = ((data.scale - data.orderScale)*data.recommendLoanAmt).toString();
  	 var amt_1 =  interceptionDouble(amt_);
  	 //alert(amt_[0]+'         '+amt_[1]+'          '+amt_[0]+'.'+amt_[1]+'        '+amt_1);
  	 td = td +"<td><span id='xh"+data.ftTSellOrderDtl.id+"'>"+tbIndex+"</span><input name='_recommendid1' id='_recommendid1"+data.ftTSellOrderDtl.id+"' type='checkbox' "+isChecked+" value='"+data.ftTSellOrderDtl.id+"' onclick= 'checkRecommend("+data.ftTSellOrderDtl.id+");'/><input type='hidden' id='loanid"+data.ftTSellOrderDtl.id+"' value="+data.investInfo.id+" ></td>";
	 td = td +"<td height='34'><span id='zqbh"+data.ftTSellOrderDtl.id+"'>"+data.loanId+"</span><span id='sellorderdtlId"+data.ftTSellOrderDtl.id+"' style='display:none;'>"+data.ftTSellOrderDtl.id+"</span></td>";
	 td = td +"<td height='34'><span id='zwr"+data.ftTSellOrderDtl.id+"'>"+data.loanName+"</span></td>";
	 td = td +"<td height='34'><span id='zwbj"+data.ftTSellOrderDtl.id+"'>"+formatCurrency(data.loanInfo.loanAMt)+"</span></td>";
	 td = td +"<td height='34'><span id='ktjbl"+data.ftTSellOrderDtl.id+"'>"+FormatNumber((data.scale - data.orderScale),4)+"</span><div id='krecommendscal"+(data.ftTSellOrderDtl.id)+"' style='display:none;'>"+(data.scale - data.orderScale)+"</div></td>";
	 td = td +"<td height='34'><div id='recommend_no_recommend_table"+data.ftTSellOrderDtl.id+"' >"+formatCurrency(amt_1)+"</div></td>";
	 td = td +"<td height='34'><span id='hkqs"+data.ftTSellOrderDtl.id+"'>"+data.loanInfo.totalNum+"</span></td>";
	 td = td +"<td height='34'><span id='syqs"+data.ftTSellOrderDtl.id+"'>"+(data.loanInfo.totalNum - data.loanInfo.currNum)+"</span></td>";
	 td = td +"<td height='34'><span id='irr"+data.ftTSellOrderDtl.id+"'>"+data.irr+"</span></td>";
	 td = td +"<td height='34'><span id='hkr"+data.ftTSellOrderDtl.id+"'>"+dictionary.get(data.investInfo.loanReturnDate)+"</span></td>";
	 td = td +"<td height='34'><span id='jkcp"+data.ftTSellOrderDtl.id+"'>"+loanCode+"</span></td>";
	 td = td +"<td height='34'><input id='tjje"+data.ftTSellOrderDtl.id+"' name='recommendmoney'  size='10' onblur='jine(this.value)' onkeyup='CalculateLoan(this,"+data.recommendLoanAmt+","+data.ftTSellOrderDtl.id+")' value='"+getRecommendValue(data.ftTSellOrderDtl.id.toString())+"'/> <div style='display:none;' id='divRecommendAmt"+data.ftTSellOrderDtl.id+"'><font color='red'>推荐比例不能大于可推荐比例!</font></div>";+"</td>";
	 td = td +"<td height='34'><div id="+divid+">"
	 			+getRecommendScal(data.ftTSellOrderDtl.id,data)+"</div><div id='cs2"
	 			+data.ftTSellOrderDtl.id+"' style='display:none;'>0</div><div id='version"
	 			+data.ftTSellOrderDtl.id+"' style='display:none;'>"+data.verson+"</div></td>";//style='display:none;'
	 td = td + "</tr>";
	 return td ;
}


function getRecommendNameArray(){
	var nameArray = new Array();
	nameArray[0]='xh:span';
	nameArray[1]='zqbh:span';
	nameArray[2]='zwr:span';
	nameArray[3]='zwbj:span';
	nameArray[4]='ktjbl:span';
	nameArray[5]='recommend_no_recommend_table:div';
	nameArray[6]='hkqs:span';
	nameArray[7]='syqs:span';
	nameArray[8]='irr:span';
	nameArray[9]='hkr:span';
	nameArray[10]='jkcp:span';
	nameArray[11]='tjje:input';
	nameArray[12]='div:div';
	nameArray[13]='sellorderdtlId:span';
	nameArray[14]='version:span';
	return nameArray;
}

function showmainform1response(responseText, statusText, xhr, $form){
 	/*alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
        '\n\nThe output div should have already been updated with the responseText.');*/
	var mainform1 = document.getElementById("mainform1");
	mainform1_page = responseText.pageObject;
	var table ='';
	if(mainform1_page.result.length>0){
		mainform1.recommend_button.disabled=false;
		GetDOMById('totalPages1').innerHTML =mainform1_page.totalPages;
	}else{
		mainform1.recommend_button.disabled=true;
		GetDOMById('totalPages1').innerHTML =1;
	}

	table = table + "<table style='width:100%;' id='mainform1table' name='mainform1table' class='ggkj_table'  border='0' cellspacing='0' cellpadding='0'> ";
	table = table+ createmainform1title();
	var td ='';
	var inde = 0;
	for(var index=0;index<mainform1_page.result.length;index++){
		inde++;
		td = td + createmainform1Rows(inde,mainform1_page.result[index]);
	}
	for(var m=inde;m<10;m++){
		td = td + mainformInsertRow2Blank(m+1);
	}
	table =table +  td +  "</table>";
	document.getElementById('mainform1table_div').innerHTML = table;
	//CheckBoxAlreadyChecked('_recommendid1','num');
}
/** 可交易债权 end*/
/** 已撮合债权 start*/
function createmainform2title(){
	 var tableStr = '';
	 tableStr  = tableStr +"</tr>";
	 tableStr  = tableStr +"<th scope='col'>序号<input  type='checkbox' id='num' style='display:none;' name='num' onclick='javascript:allChecked("+'"mainform2"'+','+'"_recommendid2"'+");' /></th>";
	 tableStr  = tableStr +"<th scope='col'>债权编号</th>";
	 tableStr  = tableStr +"<th scope='col'>债务人</th>";
	 tableStr  = tableStr +"<th scope='col'>债务本金</th>";
	 tableStr  = tableStr +"<th scope='col'>可推荐比例</th>";
	 tableStr  = tableStr +"<th scope='col'>可推荐金额</th>";
	 tableStr  = tableStr +"<th scope='col'>还款期数</th>";
	 tableStr  = tableStr +"<th scope='col'>剩余期数</th>";
	 tableStr  = tableStr +"<th scope='col'>irr</th>";
	 tableStr  = tableStr +"<th scope='col'>还款日</th>";
	 tableStr  = tableStr +"<th scope='col'>借款产品</th>";
	 tableStr  = tableStr +"<th scope='col'>推荐金额</th>";
	 tableStr  = tableStr +"<th scope='col'>推荐比例</th>";
	 tableStr  = tableStr +"</tr>";
	 return tableStr;
}

function showmainform2response(responseText, statusText, xhr, $form){
 	/*alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
        '\n\nThe output div should have already been updated with the responseText.');*/
	mainform2_page = responseText
	var table ='';
	table = table + "<table style='width:100%;' id='mainform2table' name='mainform2table' class='ggkj_table'  border='0' cellspacing='0' cellpadding='0'> ";
	table = table + createmainform2title();
	var td ='';
	var inde = 0;

	var thisformm = document.getElementById('mainform2');
	if(mainform2_page.result.length>0){
		thisformm.recommend_delete_button.disabled=false;
		thisformm.recommend_save_button.disabled=false;
		GetDOMById('totalPages2').innerHTML =mainform2_page.totalPages;
	}
	for(var index=0;index<mainform2_page.result.length;index++){
		inde++;
		td = td + createmainform2Rows(inde,mainform2_page.result[index]);
	}
	for(var m=inde;m<10;m++){
		td = td + mainformInsertRow2Blank(m+1);
	}
	table =table +  td +  "</table>";
	document.getElementById('mainform2table_div').innerHTML = table;
}
function mainformInsertRow2Blank(tbIndex){
	 var cssName = '';
	 var td = '';
	 if(Number(tbIndex)%2==1){
	 	cssName = 'ggkj_tdColr';
	 }else{
	 	cssName = '';
	 }
	 td = td + "<tr class='"+cssName+"' >";
  	 td = td +"<td></td>";
	 td = td +"<td height='34'></td>";
	 td = td +"<td height='34'></td>";
	 td = td +"<td height='34'></td>";
	 td = td +"<td height='34'></td>";
	 td = td +"<td height='34'></td>";
	 td = td +"<td height='34'></td>";
	 td = td +"<td height='34'></td>";
	 td = td +"<td height='34'></td>";
	 td = td +"<td height='34'></td>";
	 td = td +"<td height='34'></td>";
	 td = td +"<td height='34'></td>";
	 td = td +"<td height='34'></td>";
	 td = td +"</tr>";
	 return td ;
}
/** 已撮合债权 end*/

var isOutSide = false;
function CalculateLoan(v,recommendLoanAmt,selldtlId){
	var value = v.value;
	var v;
	var recommendValue = Number(v.value);
	var recommendScal = Number(FormatNumber(recommendValue/Number(recommendLoanAmt),4));
	//推荐比例
	var recommendScal2 = Number(recommendValue/Number(recommendLoanAmt));
	recommendScal2 =  FormatNumber(Number(recommendScal2),20);
	//可推荐比例
	var kcommendScal =Number(GetDivValue('krecommendscal'+selldtlId));
	var recomscalArray = recommendScal.toString().split(".");
	//特殊处理小数点问题待优化
	if(recomscalArray.length==2 && recomscalArray[1].length>4){
		recommendScal=Number(recomscalArray[0])+Number(FormatNumber(Number("0."+recomscalArray[1].substring(0,4)),4) );
	}
	document.getElementById('div'+selldtlId).innerHTML =recommendScal;
	document.getElementById('cs2'+selldtlId).innerHTML =FormatNumber(recommendScal2,18);
	//alert(recommendScal2+'     '+kcommendScal+'           '+(recommendScal2-kcommendScal).toFixed(20));
	isOutSide = Number(recommendScal2) - Number(kcommendScal ) >0.000000009;//小数点后9位
	if( isOutSide ){
		RecommendErrorData.put(selldtlId.toString());
		GetDOMById('divRecommendAmt'+selldtlId).style.display = '';
		SettingButtonStyle('recommend_button',true);
		SettingButtonStyle('recommend_save_button',true);
	}else{
		RecommendErrorData.remove(selldtlId.toString());
		GetDOMById('divRecommendAmt'+selldtlId).style.display = 'none';
		SettingButtonStyle('recommend_button',false);
		SettingButtonStyle('recommend_save_button',false);
	}
	checkRecommend(v.id);
}

function getRecommendValue(vid){
	if(RecommValueMap.get(vid)==null){
		return 0;
	}else{
		return RecommValueMap.get(vid)[11];
	}
}

function getRecommendScal(vid,data){
	var scal = formatFloat(data.ftTSellOrderDtl.scale,4);
	if(RecommValueMap.get(vid.toString())==null){
		return 0;
	}else{
		return RecommValueMap.get(vid.toString())[12];
	}
}
 // unblock when ajax activity stops 
$(document).ajaxStop($.unblockUI); 
// prepare the form when the DOM is ready 
$(document).ready(function() { 
	tablename = 'no_recommend_table';
	//ajaxsubmitRecommend();
	$.blockUI({ message: '<div><img src="${ctx}/static/images/busy.gif" /><font size="4px"> Just a moment...</font></div>' }); 
	ajaxsubmitRecommend('new');
}); 
</script>
</body>
</html>

